var Style = Vue.component('style', {
    data() {
        return {
            productInfo: []
        }
    },

    template: `<div class="style__box">
                    <div class="style__con">
                        <h3 class="index__title style__title">产品风格</h3>
                        <div class="index__info style__info">
                            <div class="index__table__list style__table__list">
                                <table class="product-class">
                                    <thead>
                                        <tr>
                                            <th>勾选</th>
                                            <th>产品名称</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr v-for="item in productInfo" :key="item.id">
                                            <td>
                                                <input type="checkbox" v-model="item.check" />
                                            </td>
                                            <td>{{ item.name }}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="common__btn">
                            <div class="common__btn__box">
                                <span class="common__btn__sure" @click="updateUserInfo">保存设置</span>
                            </div>
                        </div>
                    </div>
                </div>`,

    methods: {
        getProductInfo() {
            // 获取产品分类信息
            var self = this;
            $.ajax({
                type:"POST",
                url: _UrlPrefix + "/api/member/company/style-list",
                data: {
                    app_access: _AppAccess,
                    token: localStorage.getItem('token'),
                    type: 2,
                    cate: 2
                },
                success:function(res){
                    if(0 == res.code) {
                        self.productInfo = res.data.styles;
                    }
                }
            })
        },
        updateUserInfo() {
            // 保存产品分类信息
            let _stylesArr = [];
            for(var i = 0;i < this.productInfo.length;i++) {
                if(this.productInfo[i].check) {
                    _stylesArr.push(this.productInfo[i].id);
                }
            }
            var self = this;
            $.ajax({
                type:"POST",
                url: _UrlPrefix + "/api/member/company/com-style-set",
                data: {
                    app_access: _AppAccess,
                    token: localStorage.getItem('token'),
                    type: 2,
                    cate: 2,
                    styles: _stylesArr.join(",")
                },
                success:function(res){
                    if(0 == res.code) {
                        ELEMENT.Message.success('保存成功');
                    }
                }
            })
        }
    },
    mounted() {
        
    },
    created() {
        // 获取产品分类信息
        this.getProductInfo();
    },
})